"""
@author: 江同学呀
@file: murmur3_field.py
@date: 2024/7/27 20:21
@desc:
    https://www.elastic.co/guide/en/elasticsearch/plugins/7.17/mapper-murmur3.html

    Compute and stores hashes of values.
    计算和存储值的哈希值。
"""

from abc import ABC
from typing import Type, Union, Dict

from espc.orm.model.base.base import _Base
from espc.orm.model.mapping.field.base_field.base_field import _BaseField
from espc.utils.build_add_attr import build_add_attr


class Murmur3Field(_BaseField, ABC):
    """
    Murmur3 字段
    todo 特殊字段类型，未仔细研究文档
    """
    _field_type: str = "murmur3"

    def __init__(self, field_name: str = None, value: str = None, default: str = None, meta: Dict = None):
        super().__init__(field_name=field_name, value=value, default=default, meta=meta)
        return

    def __get__(self, instance: _Base, owner: Type["Murmur3Field"]) -> Union["Murmur3Field", str]:
        return super(Murmur3Field, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: str):
        super(Murmur3Field, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> str:
        return self._value

    @value.setter
    def value(self, value: str):
        self._value: str = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        raise NotImplementedError(f"{self.__class__.__name__}：特殊字段类型，未仔细研究文档")
